package com.ouyang.Service.Impl;

import com.ouyang.Service.LoginService;
import com.ouyang.dto.UserDto;
import com.ouyang.form.UserForm;
import com.ouyang.mapper.LoginMapper;
import com.ouyang.poji.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    public UserDto login ( UserForm user ) {
        User loginuser = loginMapper.login(user.getUsername());
        if (loginuser != null) {
            UserDto userDto = new UserDto();
            if (loginuser.getPassWord().equals(user.getPassword())) {
                userDto.setUser(loginuser);
                userDto.setCode(1);
            } else {
                userDto.setUser(null);
                userDto.setCode(-1);
            }
            return userDto;
        } else {
            UserDto userDto1 = new UserDto();
            userDto1.setCode(0);
            return userDto1;
        }
    }
}
